using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace QuanLyHocPhi.Model.Mapping
{
    public class HocPhiTinChiMap : EntityTypeConfiguration<HocPhiTinChi>
    {
        public HocPhiTinChiMap()
        {
            // Primary Key
            this.HasKey(t => t.MaHocPhiTinChi);

            // Properties
            this.Property(t => t.MaHocTap)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.MaLopHocPhan)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.TenLopHocPhan)
                .HasMaxLength(50);

            this.Property(t => t.GhiChu)
                .HasMaxLength(50);

            this.Property(t => t.SoTien).IsRequired();

            // Table & Column Mappings
            this.ToTable("HocPhiTinChi");
            this.Property(t => t.MaHocPhiTinChi).HasColumnName("MaHocPhiTinChi");
            this.Property(t => t.MaHocTap).HasColumnName("MaHocTap");
            this.Property(t => t.MaLopHocPhan).HasColumnName("MaLopHocPhan");
            this.Property(t => t.TenLopHocPhan).HasColumnName("TenLopHocPhan");
            this.Property(t => t.SoTien).HasColumnName("SoTien");
            this.Property(t => t.GhiChu).HasColumnName("GhiChu");
            this.Property(t => t.ThoiGianGhiNhan).HasColumnName("ThoiGianGhiNhan");
            this.Property(t => t.MaSinhVien).HasColumnName("MaSinhVien");
            this.Property(t => t.MaHocKy).HasColumnName("MaHocKy");
            this.Property(t => t.MaPhieuThu).HasColumnName("MaPhieuThu");
            // Relationships
            this.HasOptional(t => t.HocKy)
                .WithMany(t => t.HocPhiTinChiList)
                .HasForeignKey(d => d.MaHocKy);
            this.HasOptional(t => t.SinhVien)
               .WithMany(t => t.HocPhiTinChiList)
               .HasForeignKey(d => d.MaSinhVien);
            this.HasOptional(t => t.PhieuThu)
               .WithMany(t => t.HocPhiTinChiList)
               .HasForeignKey(d => d.MaPhieuThu);
        }
    }
}
